<!-- 父级页面:控制除了登录页以外的所有子页面的头部与左侧菜单栏 -->
<template>
  <div style="display: flex">
    <!-- 左侧菜单栏 -->
    <div :style="{ width: isCollapse ? '64px' : '208px' }">
      <el-menu
          background-color="#3c82f5"
          style="width: 100%; height: 100vh"
          text-color="#fff"
          active-text-color="#ff0"
          unique-opened
          router
          :collapse="isCollapse"
          :collapse-transition="false"
      >
        <el-row style="padding-top: 10px">
          <el-col :span="2"></el-col>
          <el-col :span="isCollapse ? 0 : 22">
            <span
                style="
                color: #fff;
                font-weight: bold;
                position: relative;
                top: 8px;
                left: 12px;
              "
            >金融信贷管理系统</span
            >
          </el-col>
        </el-row>
        <el-sub-menu index="1" style="margin-top: 20px">
          <template #title>
            <el-icon>
              <User />
            </el-icon>
            <span>信息管理</span></template
          >
          <el-menu-item index="/baseInformation">客户基本信息管理</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="2">
          <template #title>
            <el-icon>
              <Van />
            </el-icon>
            <span>关联账户管理</span></template
          >
          <el-menu-item index="/linked">关联账户管理</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="3">
          <template #title>
            <el-icon>
              <Location />
            </el-icon>
            <span>名单管理</span></template
          >
          <el-menu-item index="/whiteList">白名单管理</el-menu-item>
          <el-menu-item index="/grayList">灰名单管理</el-menu-item>
          <el-menu-item index="/blackList">黑名单管理</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="4">
          <template #title>
            <el-icon>
              <Place />
            </el-icon>
            <span>合作方管理</span></template
          >
          <el-menu-item index="/partner">合作方管理</el-menu-item>
        </el-sub-menu>
        <el-sub-menu index="5">
          <template #title>
            <el-icon><MessageBox /></el-icon>
            <span>权限管理</span></template>
            <el-menu-item index="/transfer">客户移交</el-menu-item>
            <el-menu-item index="/merge">客户合并</el-menu-item>
        </el-sub-menu>
      </el-menu>
    </div>
    <div
        :style="{
        width: isCollapse ? 'calc(100% - 64px)' : 'calc(100% - 208px)',
      }"
    >
      <!-- 右侧顶部条 -->
      <el-header
          style="padding-top: 22px; height: 10vh; background-color: #fff"
      >
        <el-row :gutter="10">
          <el-col :span="18">
            <el-icon style="font-size: 20px" @click="changeCollapsed">
              <Expand />
            </el-icon>
          </el-col>
          <el-col :span="6" style="position: relative">
            <el-dropdown
                trigger="click"
                style="position: absolute; right: 20px"
            >
              <span style="font-size: 19px; font-weight: bold">
                tom
                <el-icon><arrow-down /></el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </el-col>
        </el-row>

      </el-header>
      <!-- 右侧主体内容(可变区域) -->
      <router-view />
    </div>
  </div>
</template>

<script setup>
import { onMounted, ref } from "vue";
import { useRoute, useRouter } from "vue-router";

//定义变量用于控制左侧菜单栏是否折叠
const isCollapse = ref(false);

//定义处理菜单栏折叠的方法
const changeCollapsed = () => {
  isCollapse.value = !isCollapse.value;
};

//获取一个路由器对象
const router = useRouter();
router.beforeEach((to, from, next) => {
  next();
});
</script>
